package com.bcx.crm.java.httpServlet.ServletContextTest;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by ys on 2018/1/22.
 */
@WebServlet(urlPatterns = "/servletContext2")
public class ServletContext2 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = resp.getWriter();
        ServletContext servletContext=this.getServletContext();
        String myInfo =(String) servletContext.getAttribute("myInfo");
        writer.println("从servletContext中取出来的值是:"+myInfo+"<br/>");

        HttpSession session = req.getSession();
        String test=(String)session.getAttribute("test");
        writer.println("从session中取出来的值是:"+test+"<br/>");
    }
}
